package com.dk.controller;

import com.dk.pojo.TbFeedback;
import com.dk.result.Result;
import com.dk.service.TbFeedbackService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;



@RestController
@RequestMapping("feedback")
@Api
@ApiOperation("反馈留言")
public class TbFeedbackController {

    @Autowired
    private TbFeedbackService feedbackService;




    @GetMapping("selectAll")
    @ApiOperation(value = "查询全部（状态为0 未删除数据）")
    public Result selectAll(){
        try {
            List<TbFeedback> feedbacks = feedbackService.selectAll();
            return Result.OK().setData(feedbacks);
        } catch (Exception e) {
            e.printStackTrace();
            return Result.ER();
        }

    }


    @GetMapping("getFeedbackById/{id}")
    @ApiOperation(value = "根据id查询")
    @ApiImplicitParam(name = "id", value = "主键id", required = true, paramType = "path")
    public Result getFeedbackById(@PathVariable Long id){
        try {
            TbFeedback feedback = feedbackService.getFeedbackById(id);
            return Result.OK().setData(feedback);
        } catch (Exception e) {
            e.printStackTrace();
            return Result.ER();
        }
    }

    /**
     * 逻辑删除 将状态修改为1 不显示
     * @param feedback
     * @return
     */
    @PutMapping("updateStatusById")
    @ApiOperation(value = "逻辑删除 将状态修改为1 不显示")
    @ApiImplicitParam(name = "feedback", value = "反馈留言实体", required = true, paramType = "body")
    public Result updateStatusById(@RequestBody TbFeedback feedback){
        try {
            feedbackService.updateStatusById(feedback);
            return Result.OK();
        } catch (Exception e) {
            e.printStackTrace();
            return Result.ER();
        }
    }


}
